﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace PaintDotNetForms
{
    public class RectangleShape : Figure
    {        
        override public void draw(System.Drawing.Graphics g)
        {
            int x = startPoint.X, y = startPoint.Y;
            
            int width = Math.Abs(endPoint.X - startPoint.X);
            int height = Math.Abs(endPoint.Y - startPoint.Y);

            if (endPoint.X < startPoint.X)           
                x = endPoint.X;

            if (endPoint.Y < startPoint.Y)            
                y = endPoint.Y;

            if (ShiftIsDown)
            {                
                height = width;
            }

            switch (Filling)
            {
                case Filling.Outline:
                    g.DrawRectangle(pen, x, y, width, height);
                    break;
                case Filling.Filled:
                    g.FillRectangle(brush, x, y, width, height);
                    break;
                case Filling.FilledWithOutline:
                    g.DrawRectangle(pen, x, y, width, height);
                    g.FillRectangle(brush, x, y, width, height);
                    break;
            }

            if (SizeChangeEvent != null)
                SizeChangeEvent(new Size(width, height));
        }

        public override event SizeChange SizeChangeEvent;
    }
}
